package com.awenhui.demo.config.shiro;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

/**
 * @author yuxf
 * @version 1.0
 * @date 2020/12/21 16:12
 */
@Service
public class TestShiroUserService {

    Logger logger = LoggerFactory.getLogger(getClass());

    public UserDto loadUserByUserName(String userName) {
        logger.info("从数据库加载用户{}信息", userName);
        UserDto userDto = new UserDto();
        if (userName.equals("admin") || userName.equals("demo")) {
            int i = new Random().nextInt(10);
            userDto.setId(i);
            userDto.setRealName("何刘惠" + i);
            userDto.setUserName("admin" + i);
            userDto.setPassword("147ff12b4fe96c7e15fdd6001769967d");//123456-abc
            userDto.setSalt("abc");
            return userDto;
        } else {
            return null;
        }
    }

    /**
     * 获取角色
     *
     * @return
     */
    public Set<String> getRoles() {
        logger.info("从数据库加载角色信息");
        Set<String> roles = new HashSet<>();
        roles.add("admin");
        roles.add("demo");
        return roles;
    }
}
